$(function() {
    setTimeout(cleanSessionConfig, 1000);
});
function cleanSessionConfig() {
    $.post(baseUrl + "/config/cleansession/", {}, "", "json");
}
function enterKeyBackup() {
  $(":input", diagBackup).keypress(function(a) {
    if(a.which && a.which == 13 || a.keyCode && a.keyCode == 13) {
      diagBackup.dialog("close");
      makeBackup();
      return false
    }
  })
}
function dialogBackup() {
  if(tabulaireTable == undefined) {
    alertGrowl(MISC_ERROR, VISU_ERROR_EMPTYSEARCH)
  }else {
    getListUser();
    var btns = {};
    btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
    btns[BUTTON_SAVE] = function() {$(this).dialog("close"); makeBackup()};
    diagBackup.dialog({autoOpen:false, draggable:true, width:"auto", modal:true, buttons:btns});
    diagBackup.dialog("open")
  }
}
function makeBackup(b, c) {
  if(b != false) {
    var a = arrayRow(2);
    if(a.length == 0) {
      alertGrowl(MISC_ERROR, VISU_ERROR_EMPTYSELECT);
      return false
    }
  }else {
    a = c;
  }
  $.post(baseUrl + "/config/backup/", {model:$("#listModelBackup :selected").text(), type:$("#listTypeBackup :selected").text(), identity:$("#listUserBackup :selected").text(), proto:$("#listProtocolBackup :selected").text(), ip:a.toString()}, attenteReponse, "json");
  return true
}
function backupResp(a) {
  a = a.split(",");
  for(var b = 0, c = a.length;b < c;b++) {
    var d = a[b].split(";");
    if (d[0] != "") {
        d[0] ? alertGrowl(VISU_BACKUP_SAVE + ' ' + d[1], VISU_BACKUP_SUCESS) : alertGrowl(VISU_BACKUP_SAVE + ' ' + d[1], VISU_BACKUP_UNSUCESS);
    }
  }
  refreshTree()
}
function getListUser() {
  $.post(baseUrl + "/log/getlistuser/", {}, selectFilterBaseModel, "json")
}
function restoreResp(a) {
  a.result == 0 ? alertGrowl(VISU_RESTORE_TXT, VISU_RESTORE_SUCESS) : alertGrowl(VISU_RESTORE_TXT, VISU_RESTORE_UNSUCESS);
}
function enterKeyRestore() {
  $(":input", diagRestore).keypress(function(a) {
    if(a.which && a.which == 13 || a.keyCode && a.keyCode == 13) {
      diagRestore.dialog("close");
      makeRestore();
      return false
    }
  })
}
function dialogRestore() {
  if(tabulaireTable == undefined) {
    alertGrowl(MISC_ERROR, VISU_ERROR_EMPTYSEARCH)
  }else {
    getListUser();
    getListConf();
    var btns = {};
    btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
    btns[BUTTON_RESTORE] = function() {$(this).dialog("close"); makeRestore()};
    diagRestore.dialog({autoOpen:false, draggable:true, width:"auto", modal:true, buttons:btns});
    diagRestore.dialog("open")
  }
}
function makeRestore(b, c) {
  if(b != false) {
    var a = arrayRow(2);
    if(a.length > 1 || a.length == 0) {
      alertGrowl(MISC_ERROR, VISU_ERROR_ENOUGHTSELECT);
      return false
    }
  }else {
    a = c
  }
  $.post(baseUrl + "/config/restore/", {conf:$("#listConfRestore :selected").val(), model:$("#listModelRestore :selected").text(), type:$("#listTypeRestore :selected").text(), identity:$("#listUserRestore :selected").text(), proto:$("#listProtocolRestore :selected").text(), ip:a.toString()}, attenteReponse, "json");
  return true
}
function getListConf(b, c) {
 var a = b != false ? arrayRow(2) : c;
 $.post(baseUrl + "/config/getlistconf/", {ip:a.toString()}, selectRestoreBaseConf, "json");
}
function getConfDiff(a) {
  confEnCour = a.attributes[0].value;
  $.ajax({type:"POST", url:baseUrl + "/config/printdiffconf/", success:confDiff, dataType:"json", async:false, data:({idconf:confEnCour})});
}
function confDiff(a) {
  var c = $("#divConfDiff");
  c.find("*").remove();
  c.append(a.result)
}
function deleteConfDiff() {
  $.post(baseUrl + "/config/deleteconf/", {idconf:confEnCour}, null, "json");
  var indexNumber = $tabs.tabs('option', 'selected');
  if (indexNumber != 0)
    $("#tabs").tabs("remove", indexNumber);
  var conftree = $("#divConfTree");
  conftree.find("*").remove();
  getListDiffConf();
  alertGrowl(VISU_CONFIGURATION, MISC_DEL)
}
valid.add("deleteConfDiff", deleteConfDiff);
function downloadConfig() {
    $.post(baseUrl + "/config/getconf/", {idconf:confEnCour}, openConfig, "json")
}
function openConfig(a) {
    window.open(baseUrl + '/public/tmp/' + a.name);
}
function compareConfig() {
    var a = $("#listConfDiff :selected").val();
    $.post(baseUrl + "/config/diffconf/", {idconf:confEnCour,idconf2:a}, confDiff, "json")
}
function dialogConfig() {
    getListConfAll()
    var a = $("#dialogDiffConf");
    var btns = {};
    btns[BUTTON_CANCEL] = function() {$(this).dialog("close")};
    btns[BUTTON_COMPARE] = function() {$(this).dialog("close"); compareConfig()};
    a.dialog({autoOpen:false, draggable:true, width:"auto", modal:true, buttons:btns});
    a.dialog("open")
}
function getListConfAll() {
    $.post(baseUrl + "/config/getlistconfall/", {}, selectRestoreBaseConf, "json")
}